<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>写消息</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/lang/zh-cn/zh-cn.js"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                	<!-- <a class="mini-button" onclick="submitForm()"><i class="fa fa-paper-plane"></i> 发送</a> -->
                    <a class="mini-button" onclick="openSelectUsersWindow()">
                    	<i class="fa fa-user-plus fa-lg"></i> 选择接收人</a>
               		<span id="realnames" style="color: red;">未选择接收人</span>
                </td>
                <td style="white-space:nowrap;">
                	
                </td>
            </tr>
        </table>           
    </div>
  	
  	<form id="customerForm" method="post" style="padding: 10px;">
  		<input id="userIds" type="hidden" />
  		<table>
  			<tr>
  				<td width="40">
  					<label>标题：</label>
  				</td>
  				<td>
  					<input id="title" name="title" width="300" class="mini-textbox" emptyText="选填" />
  				</td>
  			</tr>
  			<tr>
  				<td valign="top" width="40">
  					<label>内容：</label>
  				</td>
  				<td>
  					<script id="editor" type="text/plain" style="height:300px; width:650px;">
						
					</script>
  				</td>
  			</tr>
  		</table>
  	</form>
  	
  	<div class="mini-toolbar" style="width: 100%; padding: 5px; position: fixed; bottom: 0px;" borderStyle="border:0;">
        <a class="mini-button" onclick="submitForm()"><i class="fa fa-paper-plane"></i> 发送</a>
    </div>
  	
  	
	<script type="text/javascript">
		var ue;
		var $userIds;
		var $realnames;
	
		$(function(){
			ue = UE.getEditor("editor", {
				toolbars: [["fullscreen","source","undo","redo","preview",,"emotion","insertunorderedlist",
				            "insertorderedlist","bold","forecolor","justifyleft","justifycenter","justifyright",
				            "justifyjustify","removeformat","formatmatch","simpleupload","insertimage","attachment"]],
				autoHeightEnabled:false
			});
			$userIds = $("#userIds");
			$realnames = $("#realnames")
		});
		
		
		function openSelectUsersWindow(){
			mini.open({
                url: "rp/system/msg/selectUsers.jsp",
                title: "<i class='fa fa-user-plus fa-lg'></i> 选择接收人", 
                width: 400, 
                height: 400,
                //showMaxButton: true,
                onload: function () {
                	var iframe = this.getIFrameEl();
                  	iframe.contentWindow.init();
                },
                ondestroy: function (action) {
                	if (action == "ok") {
                        var iframe = this.getIFrameEl();
						var userIds = iframe.contentWindow.getSelectData();
						var realnames = iframe.contentWindow.getSelectRealname();
						$userIds.val(userIds);
						$realnames.text(realnames);
                    }
                }
            });
		}
		
		function closeWindow(action) {
	        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	        else window.close();
	    }
		
		function submitForm(){
			if($realnames.text() === "未选择接收人"){
				mini.alert("请先选择接收人");
				return;
			}else{
				rp_ajax("rp/system/msg/sendMessage", 
						{userIds:$userIds.val(), 
						 title:mini.get("title").getValue(), 
						 content: ue.getContent(),
						 receiver:$realnames.text()}, function(result){
							if(result == "success"){
								//mini.alert("发送成功");
								closeWindow("ok");
							}else{
								mini.alert(result);
							}
						});
			}
			
		}
	</script>
  </body>
</html>
